package com.google.code.cubeirc.scripting;

import com.google.code.cubeirc.queue.MessageQueue;
import com.google.code.cubeirc.queue.MessageQueueEnum;

public class BaseCommands {

	public void echo(String text)
	{
		MessageQueue.addQueue(MessageQueueEnum.CONSOLE, text);
	}
	
	public void join(String channel)
	{
		MessageQueue.addQueue(MessageQueueEnum.CHANNEL_USR_JOIN, channel);
	}
	
	/**
	 * Help.
	 *
	 * @param cmd the cmd
	 */
	
	public void help(String cmd)
	{
		String cmd_help = "";
		String cmd_file = "";
		for(Script s : ScriptManager.scripts){
			if(s.getFunctions().contains(cmd)){
				cmd_help = s.getFunc_help().get(cmd);
				cmd_file = s.getReference().getName();
			}
		}

		if (cmd_help != "")
			MessageQueue.addQueue(MessageQueueEnum.CONSOLE, String.format("[%s] - /%s: %s",  cmd_file ,cmd, cmd_help));
		else
		{
			MessageQueue.addQueue(MessageQueueEnum.CONSOLE,"HELP for all commands:");
			MessageQueue.addQueue(MessageQueueEnum.CONSOLE, "----");
			for(Script s : ScriptManager.scripts){

				for (String key : s.getFunc_help().keySet())
				{
					MessageQueue.addQueue(MessageQueueEnum.CONSOLE, String.format("[%s] - /%s: %s", s.getReference().getName(), key, s.getFunc_help().get(key)));
				}
			}
		}

	}
}
